
<%@include file="/libs/foundation/global.jsp" %>
<cq:includeClientLib categories="scriptsLibraries"/>

<%@ page import="com.day.cq.wcm.foundation.forms.FormsHelper,
                   com.day.cq.wcm.foundation.forms.LayoutHelper,
                   java.util.Collections,
                   java.util.List,
                   java.util.Map,
                   java.util.Locale,
                   java.util.ResourceBundle,
                   com.day.cq.i18n.I18n,
                   org.apache.commons.lang3.StringEscapeUtils" %><%
    
    final Locale pageLocale = currentPage.getLanguage(true);
    final ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLocale);
    I18n i18n = new I18n(resourceBundle); 
                    
    final String name = FormsHelper.getParameterName(resource);
    final String id = FormsHelper.getFieldId(slingRequest, resource);
    final boolean required = FormsHelper.isRequired(resource);
    final boolean hideTitle = properties.get("hideTitle", false);
    final String title = FormsHelper.getTitle(resource, i18n.get("Selection"));

    final List<String> values = FormsHelper.getValuesAsList(slingRequest, resource);

    Map<String, String> displayValues = FormsHelper.getOptions(slingRequest, resource);
    if (displayValues == null) {
        displayValues = Collections.singletonMap("item1", i18n.get("Item 1"));
    }


    int i = 0;
    for (String v : displayValues.keySet()) {
        final String t = displayValues.get(v);
        final String currentId = id + "-" + i;

    %><div class="form_row"><%
        LayoutHelper.printTitle(currentId, t, false, true, out);
        %><div class="checkText" class="form_rightcol"><%

                String checked = "";
                if (values.contains(v)) {
                    checked = " checked=\"checked\"";
                }
            %>
            <div class="contentCheck">
                    <input class="check" class="<%= FormsHelper.getCss(properties, "form_field form_field_checkbox") %>" type="checkbox"
                             id="<%= StringEscapeUtils.escapeHtml4(currentId) %>" name="<c:out value="<%= name %>"/>"
                             value="<c:out value="<%= v %>"/>" <%= checked %>>
                                <%
                                   String desc=properties.get("text","");
                                   if(desc.length()>0){
                                        desc=desc.substring(3,desc.length());
                                        desc=desc.substring(0,desc.length()-5);
                                    }
                             %> <%=desc %>          
                    </input>
             </div>
        </div>
    </div><%

        i++;
    }

    LayoutHelper.printDescription(FormsHelper.getDescription(resource, ""), out);
    LayoutHelper.printErrors(slingRequest, name, hideTitle, out);
%>


